package com.woniu.outpatient.service.impl;

import java.util.Date;
import java.util.List;

import com.woniu.outpatient.domain.CheckRecordVo;
import com.woniu.outpatient.domain.MoneyTotalVO;
import com.woniu.outpatient.domain.TimesVo;
import com.woniu.outpatient.service.IDoctorService;
import com.woniu.outpatient.service.UserDeptAndDoctorService;
import com.woniu.user.service.IPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.woniu.outpatient.mapper.CheckrecordMapper;
import com.woniu.outpatient.domain.Checkrecord;
import com.woniu.outpatient.service.ICheckrecordService;

import javax.annotation.Resource;

/**
 * 检查流水表Service业务层处理
 *
 * @author wolf-six
 * @date 2023-02-15
 */
@Service
public class CheckrecordServiceImpl implements ICheckrecordService
{
    @Resource
    private CheckrecordMapper checkrecordMapper;
    @Autowired
    private IDoctorService iDoctorService;

    @Autowired
    private UserDeptAndDoctorService userDeptAndDoctorService;

    @Override
    public List<MoneyTotalVO> checkMoneyTotal(TimesVo timesVo) {
         List<MoneyTotalVO> moneyTotalVOS = checkrecordMapper.checkMoneyTotal(timesVo);
        for (MoneyTotalVO item: moneyTotalVOS) {
            item.setDoctorName(iDoctorService.getDoctorNameById(Long.parseLong(String.valueOf(item.getDoctorId()))));

           item.setPatientName(iDoctorService.getpatientNameById( Long.parseLong(String.valueOf(item.getPatientId()))));
            item.setDeptName(userDeptAndDoctorService.selectById(Long.parseLong(String.valueOf(item.getDeptId()))).getDeptName());
           ;
        }

        return moneyTotalVOS;
    }

    /**
     * 查询检查流水表
     *
     * @param checkrecordId 检查流水表主键
     * @return 检查流水表
     */
    @Override
    public Checkrecord selectCheckrecordByCheckrecordId(Long checkrecordId)
    {
        return checkrecordMapper.selectCheckrecordByCheckrecordId(checkrecordId);
    }

    /**
     * 查询检查流水表列表
     *
     * @param checkrecord 检查流水表
     * @return 检查流水表
     */
    @Override
    public List<Checkrecord> selectCheckrecordList(Checkrecord checkrecord)
    {

        return checkrecordMapper.selectCheckrecordList(checkrecord);
    }

    @Override
    public List<Checkrecord> selectCheckrecordListYLL(Checkrecord checkrecord) {
        return checkrecordMapper.selectCheckrecordListYLL(checkrecord);
    }

    public List<Checkrecord> showAll(Checkrecord checkrecord)
    {
        List<Checkrecord> CheckrecordAll  =checkrecordMapper.selectCheckrecordList(checkrecord);

        return checkrecordMapper.selectCheckrecordList(checkrecord);

    }
    /**
     * 新增检查流水表
     *
     * @param checkrecord 检查流水表
     * @return 结果
     */
    @Override
    public int insertCheckrecord(Checkrecord checkrecord)
    {
        checkrecord.setCheckrecordStatus("未检查");
        return checkrecordMapper.insertCheckrecord(checkrecord);
    }

    /**
     * 修改检查流水表
     *
     * @param checkrecord 检查流水表
     * @return 结果
     */
    @Override
    public int updateCheckrecord(Checkrecord checkrecord)
    {
        return checkrecordMapper.updateCheckrecord(checkrecord);
    }

    @Override
    public int updateStatusResultById(CheckRecordVo checkrecordVo) {
        if(checkrecordVo.getCheckrecordStatus().equals("已检查")){
        checkrecordVo.setChenckTime(new Date());
        }
        return checkrecordMapper.updateStatusResultById(checkrecordVo);
    }

    /**
     * 批量删除检查流水表
     *
     * @param checkrecordIds 需要删除的检查流水表主键
     * @return 结果
     */
    @Override
    public int deleteCheckrecordByCheckrecordIds(Long[] checkrecordIds)
    {
        return checkrecordMapper.deleteCheckrecordByCheckrecordIds(checkrecordIds);
    }

    /**
     * 删除检查流水表信息
     *
     * @param checkrecordId 检查流水表主键
     * @return 结果
     */
    @Override
    public int deleteCheckrecordByCheckrecordId(Long checkrecordId)
    {
        return checkrecordMapper.deleteCheckrecordByCheckrecordId(checkrecordId);
    }
}
